package javabasics.thread.sallticket;

public class Station extends Thread {

    //通过构造方法给线程赋值
    public Station(String name){
        super(name);
    }

    //共享资源变量--总票数
    static int ticket = 20;

    //创建一个静态钥匙
    static Object ob = "aa";
    @Override
    public void run() {

        while (ticket>0){
            synchronized (ob){
                if(ticket>0){
                    System.out.println(getName() + "卖出了第" + ticket + "张票");
                    ticket--;
                }else {
                    System.out.println("票卖完了");
                }
            }
            try{
                sleep(1000);//休息1秒
            }catch (InterruptedException e){
                e.printStackTrace();
            }

        }
    }


}
